package UILayer;
import java.util.Scanner;


/**
 * MainMenu of the program where you have access to all other menues.
 * 
 * @author Group1
 * @version 2011-06-05
 */
public class MainUI
{
    // instance variables - replace the example below with your own
    private Scanner reader;
    private SupplierUI supplierUI;
    private ItemUI itemUI;
    private OrderUI orderUI;
    private PersonUI personUI;
    private SaleUI saleUI;
    private RentalUI rentalUI;
    private String loginName;
    
    /**
     * Creates the reader and starts the menu.
     * @param loginName The loginName is recieved from the LoginUI and is used to decide
     * accesslevel
     */
    public MainUI(String loginName)
    {
        reader = new Scanner(System.in);
        this.loginName = loginName;
        start();
    }
    
    /**
     * Prints the MainMenu on the screen.
     */
    private void writeMenu()
    {
        System.out.println("\f*** Main Menu ***");
        System.out.println("(1)  Order");
        System.out.println("(2)  Make sale");
        System.out.println("(3)  Item/Stock");
        System.out.println("(4)  Supplier");
        System.out.println("(5)  Person");
        System.out.println("(6)  Machines");
        System.out.println("");
        System.out.println("(0)  Logout");
        System.out.println("");
        System.out.print("make choise: ");
    }
    
    /**
     * Loop where the user have to chose an option.
     */
    public void start()
    {
        boolean stop = false;
        while(!stop) {
            writeMenu();
            int i = UIInput.inputInt();
            if(i ==1) 
            {
                orderUI = new OrderUI();
            }
            if(i ==2) 
            {
                saleUI = new SaleUI();
            }
            if(i ==3) 
            {
                itemUI = new ItemUI(loginName);
            }
            if(i ==4) 
            {
                supplierUI = new SupplierUI();
            }
            if(i ==5) 
            {
                personUI = new PersonUI();
            }
            if(i ==6)
            {
                rentalUI = new RentalUI();
            }
            if(i ==0) 
            {
               stop = true;
               System.out.print("\f");
               System.out.println("Exit the program by enter 'exit' as loginname");
            }
        }
    }    
}
